package cn.zust.edu.cn;

public class Triangle implements IShape {
    Point ptA;
    Point ptB;
    Point ptC;
    double edgeA;
    double edgeB;
    double edgeC;

    public Triangle(Point ptA, Point ptB, Point ptC) {
        this.ptA = ptA;
        this.ptB = ptB;
        this.ptC = ptC;
        this.edgeA = calculateDistance(ptA, ptB);
        this.edgeB = calculateDistance(ptB, ptC);
        this.edgeC = calculateDistance(ptC, ptA);
    }

    private double calculateDistance(Point p1, Point p2) {
        return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
    }

    @Override
    public double perimeter() {
        return edgeA + edgeB + edgeC;
    }

    @Override
    public double area() {
        double s = perimeter() / 2;
        return Math.sqrt(s * (s - edgeA) * (s - edgeB) * (s - edgeC));
    }

    @Override
    public void draw() {
        System.out.println("Drawing Triangle with vertices (" + ptA.x + ", " + ptA.y + "), (" + ptB.x + ", " + ptB.y + "), (" + ptC.x + ", " + ptC.y + ")");
    }
}